<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="workspace.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>workspace.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'workspace.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="workspace.html">workspace</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * Manages components of the workspace like edition areas, toolboxes, property boxes and instruction boxes.
 * <span class="attrib">@author</span> Roosevelt de Lima Sardinha
 * <span class="attrib">@constructor</span>
 */</span>
<span class="reserved">function</span> workspace(){
	<span class="comment">/**
	 * The id of the workspace.
	 */</span>
	<span class="reserved">this</span>.id = null;
	
	<span class="comment">/**
	 * The profile that is being used by the toolbox.
	 * <span class="attrib">@type</span> {Int}
	 */</span>
	<span class="reserved">this</span>.activeProfile = null;
	
	<span class="comment">/**
	 * Array that keeps all edition areas in this workspace.
	 * <span class="attrib">@type</span> {Array}
	 */</span>
	<span class="reserved">this</span>.editionAreas = new Array;

	<span class="comment">/**
	 * Array that keeps all edition areas in this workspace.
	 * <span class="attrib">@type</span> {Array}
	 */</span>
	<span class="reserved">this</span>.propertyBoxes = new Array;
	
	<span class="comment">/**
	 * Array that keeps all instruction boxes in this workspace.
	 * <span class="attrib">@type</span> {Array}
	 */</span>
	<span class="reserved">this</span>.instructionBoxes = new Array;
	
	<span class="comment">/**
	 * Array that keeps all edition areas in this workspace.
	 * <span class="attrib">@type</span> {Array}
	 */</span>
	<span class="reserved">this</span>.toolBoxes = new Array;
	
	<span class="comment">/**
	 * Array that keeps all profiles in this workspace.
	 * <span class="attrib">@type</span> {Array}
	 */</span>
	<span class="reserved">this</span>.profiles = new Array;
	
	<span class="comment">/**
	 * Takes the keyboard object that is being used for taking care of key pressing in the workspace.
	 * <span class="attrib">@type</span> {Object}
	 */</span>
	<span class="reserved">this</span>.keyboard = new keyboard();
	
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken before creating an editionArea.
	 */</span>
	<span class="reserved">this</span>.onBeforeCreateEditionArea = <span class="reserved">function</span>(){};
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken before creating a propertyBox.
	 */</span>
	<span class="reserved">this</span>.onBeforeCreateToolBox = <span class="reserved">function</span>(){};
	
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken before creating a propertyBox.
	 */</span>
	<span class="reserved">this</span>.onBeforeCreatePropertyBox = <span class="reserved">function</span>(){};
	
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken before creating an InstructionBox.
	 */</span>
	<span class="reserved">this</span>.onBeforeCreateInstructionBox = <span class="reserved">function</span>(){};
	
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken after creating an edition area.
	 */</span>
	<span class="reserved">this</span>.onAfterCreateEditionArea = <span class="reserved">function</span>(editionArea){};
	
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken after creating a toolbox.
	 */</span>
	<span class="reserved">this</span>.onAfterCreateToolBox = <span class="reserved">function</span>(toolBox){};
	
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken after creating a property box.
	 */</span>
	<span class="reserved">this</span>.onAfterCreatePropertyBox = <span class="reserved">function</span>(propertyBox){};
	
	<span class="comment">/**
	 * &lt;b&gt;Event&lt;/b&gt;&lt;br/&gt;
	 * Defines what action is going to be taken after creating an instruction box.
	 */</span>
	<span class="reserved">this</span>.onAfterCreateInstructionBox = <span class="reserved">function</span>(instructionBox){};

	<span class="comment">/**
	 * Creates an edition area.
	 * <span class="attrib">@param</span> {String} id The unique id of this edition area
	 * <span class="attrib">@param</span> {Object} properties The properties to change attributes like left, top, width, height, parent, and others
	 * <span class="attrib">@return</span> The edition area created with the properties set.
	 * <span class="attrib">@type</span> {Object} 
	 */</span>
    <span class="reserved">this</span>.createEditionArea = <span class="reserved">function</span>(id, properties){
        <span class="reserved">this</span>.onBeforeCreateEditionArea();
		<span class="comment">// Creates an Edition Area that can receive EOs.</span>
        var ea = new editionArea(id, {
			left: properties.left,
			top: properties.top, 
			width: properties.width, 
			height: properties.height, 
			parent: properties.parent,
			toolBox: properties.toolBox, 
			propertyBox: properties.propertyBox, 
			instructionBox: properties.instructionBox,
			workspace: <span class="reserved">this</span>
		});
        <span class="reserved">this</span>.editionAreas.push(ea);
		
		<span class="comment">// Calling Event</span>
		<span class="reserved">this</span>.onAfterCreateEditionArea(ea);	
        <span class="reserved">return</span> ea;
    }
	
	 <span class="comment">/**
	 * Creates a tool box.
	 * <span class="attrib">@param</span> {String} id The unique id of this tool box
	 * <span class="attrib">@param</span> {Object} properties The properties to change attributes like left, top, width, height, parent, and others
	 * <span class="attrib">@return</span> The toolbox created with the properties set.
	 * <span class="attrib">@type</span> {Object} 
	 */</span>   
    <span class="reserved">this</span>.createToolBox = <span class="reserved">function</span>(id, properties){
        <span class="reserved">this</span>.onBeforeCreateToolBox();
		<span class="comment">// Create a Toolbox where you can add some tools.</span>
        var tb = new toolBox(id, {
			left: properties.left,
		    top: properties.top, 
			width: properties.width,
			height: properties.height,
			parent: properties.parent,
			workspace: <span class="reserved">this</span>
			});
        <span class="reserved">this</span>.toolBoxes.push(tb);
		
		<span class="comment">// Calling Event</span>
		<span class="reserved">this</span>.onAfterCreateToolBox(tb);
        <span class="reserved">return</span> tb;
    }
    
	 <span class="comment">/**
	 * Creates a property box.
	 * <span class="attrib">@param</span> {String} id The unique id of this property box
	 * <span class="attrib">@param</span> {Object} properties The properties to change attributes like left, top, width, height, parent, and others
	 * <span class="attrib">@return</span> The property box created with the properties set.
	 * <span class="attrib">@type</span> {Object} 
	 */</span> 	
    <span class="reserved">this</span>.createPropertyBox = <span class="reserved">function</span>(id, properties){
        <span class="reserved">this</span>.onBeforeCreatePropertyBox();
		
		<span class="comment">// Create a box with the properties of the selected objects.</span>
        var pb = new propertyBox(id, {
			left: properties.left,
		    top: properties.top, 
			width: properties.width,
			height: properties.height,
			parent: properties.parent,
			workspace: <span class="reserved">this</span>
			});
        <span class="reserved">this</span>.propertyBoxes.push(pb);
        
		<span class="comment">// Calling Event</span>
		<span class="reserved">this</span>.onAfterCreatePropertyBox(pb);
		<span class="reserved">return</span> pb;
    }
    
	
	<span class="comment">/**
	 * Creates an instruction box.
	 * <span class="attrib">@param</span> {String} id The unique id of this instruction box
	 * <span class="attrib">@param</span> {Object} properties The properties to change attributes like left, top, width, height, parent, and others
	 * <span class="attrib">@return</span> The instruction box created with the properties set.
	 * <span class="attrib">@type</span> {Object} 
	 */</span> 
    <span class="reserved">this</span>.createInstructionBox = <span class="reserved">function</span>(id, properties){
        <span class="reserved">this</span>.onBeforeCreateInstructionBox();
		<span class="comment">// Creates a box with instruction for helping users using kiwi.</span>
        var ib = new instructionBox(id, {
			left: properties.left,
		    top: properties.top, 
			width: properties.width,
			height: properties.height,
			parent: properties.parent,
			workspace: <span class="reserved">this</span>
			});
        <span class="reserved">this</span>.instructionBoxes.push(ib);
		
		<span class="comment">// Calling Event</span>
		<span class="reserved">this</span>.onAfterCreateInstructionBox(ib);
        <span class="reserved">return</span> ib;
    }
	
	<span class="reserved">function</span> search(elementId, array){
        var index = -1;
        <span class="reserved">for</span> (var i = 0; i &lt; array.length; i++) {
            <span class="reserved">if</span> (array[i].id == elementId) {
                index = i;
                break;
            }
        }
        
        <span class="reserved">if</span> (index != -1) {
            <span class="reserved">return</span> {obj: array[index], index: index};
        }
        <span class="reserved">else</span> {
            <span class="reserved">return</span> index;
        }
	}
	
	<span class="comment">/**
	 * Returns an edition area given its id 
	 * <span class="attrib">@param</span> {String} id The id of the edition area to be returned
	 * <span class="attrib">@return</span> The edition area that has the given id.
	 * <span class="attrib">@type</span> {Object}
	 */</span>	
	<span class="reserved">this</span>.getEditionAreaById =  <span class="reserved">function</span>(id){
		<span class="reserved">return</span> search(id, <span class="reserved">this</span>.editionAreas).obj;		
	}

	<span class="comment">/**
	 * Returns a property box given its id 
	 * <span class="attrib">@param</span> {String} id The id of the property box to be returned
	 * <span class="attrib">@return</span> The property box that has the given id
	 * <span class="attrib">@type</span> {Object}
	 */</span>		
	<span class="reserved">this</span>.getPropertyBoxById = <span class="reserved">function</span>(id){
		<span class="reserved">return</span> search(id, <span class="reserved">this</span>.propertyBoxes).obj;
	}

	<span class="comment">/**
	 * Returns an instruction box given its id 
	 * <span class="attrib">@param</span> {String} id The id of the instruction box to be returned
	 * <span class="attrib">@return</span> The instrcution box that has the given id
	 * <span class="attrib">@type</span> {Object}
	 */</span>			
	<span class="reserved">this</span>.getInstructionBoxById = <span class="reserved">function</span>(id){
		<span class="reserved">return</span> search(id, <span class="reserved">this</span>.instructionBoxes).obj;
	}
	
	
	<span class="comment">/**
	 * Returns a tool box given its id 
	 * <span class="attrib">@param</span> {String} id The id of the tool box to be returned
	 * <span class="attrib">@return</span> The tool box that has the given id
	 * <span class="attrib">@type</span> {Object}
	 */</span>		
	<span class="reserved">this</span>.getToolBoxById = <span class="reserved">function</span>(id){
		<span class="reserved">return</span> search(id, <span class="reserved">this</span>.toolBoxes).obj;
	}
	
	
	<span class="reserved">function</span> remove(id, array ){
		var element = search(id, array);
		element.obj.remove();
		array.splice(element.index, 1);
		delete element;
	}
	
	<span class="comment">/**
	 * Removes an edition area given its id 
	 * <span class="attrib">@param</span> {String} id  The id of the edition area 
	 */</span>		
	<span class="reserved">this</span>.removeEditionArea = <span class="reserved">function</span>(id){
		remove(id, <span class="reserved">this</span>.editionAreas);
	}

	<span class="comment">/**
	 * Removes a property box given its id 
	 * <span class="attrib">@param</span> {String} id  The id of the property box 
	 */</span>		
	<span class="reserved">this</span>.removePropertyBox = <span class="reserved">function</span>(id){
		remove(id, <span class="reserved">this</span>.propertyBoxes);
	}
	
	<span class="comment">/**
	 * Removes an instruction box given its id 
	 * <span class="attrib">@param</span> {String} id  The id of the instruction box 
	 */</span>			
	<span class="reserved">this</span>.removeInstructionBox = <span class="reserved">function</span>(id){
		remove(id, <span class="reserved">this</span>.instructionBoxes);
	}
	
	<span class="comment">/**
	 * Removes a toolBox given its id 
	 * <span class="attrib">@param</span> {String} id  The id of the toolBox 
	 */</span>		
	<span class="reserved">this</span>.removeToolBox = <span class="reserved">function</span>(id){
		remove(id, <span class="reserved">this</span>.toolBoxes);
	}
	
	<span class="reserved">function</span> retrieveByIndex(index, array){
		<span class="reserved">if</span> (array.length &gt;= index){
			<span class="reserved">return</span> null;
		}<span class="reserved">else</span>{
			<span class="reserved">return</span> array[index];
		}
	}
	
	<span class="comment">/**
	 * Returns an edition area by its index
	 * <span class="attrib">@param</span> {Int} index The position of the edition area in the editionAreas array. It depends on the order of creation.
	 * <span class="attrib">@return</span> The edition area corresponding to the given index
	 * <span class="attrib">@type</span> {object}
	 */</span>	
	<span class="reserved">this</span>.getEditionAreaByIndex = <span class="reserved">function</span>(index){
		<span class="reserved">return</span> retrieveByIndex(index,<span class="reserved">this</span>.editionAreas); 
	}

	<span class="comment">/**
	 * Returns a property box by its index
	 * <span class="attrib">@param</span> {Int} index The position of the property box in the propertyBoxes array. It depends on the order of creation.
	 * <span class="attrib">@return</span> The property box corresponding to the given index
	 * <span class="attrib">@type</span> {Object}
	 */</span>	
	<span class="reserved">this</span>.getPropertyBoxByIndex = <span class="reserved">function</span>(index){
		<span class="reserved">return</span> retrieveByIndex(index,<span class="reserved">this</span>.propertyBoxes);
	}

	<span class="comment">/**
	 * Returns an instruction box by its index
	 * <span class="attrib">@param</span> {Int} index The position of the instruction box in the instructionBoxes array. It depends on the order of creation.
	 * <span class="attrib">@return</span> The instruction box corresponding to the given index
	 * <span class="attrib">@type</span> {Object}
	 */</span>		
	<span class="reserved">this</span>.getInstructionBoxByIndex = <span class="reserved">function</span>(index){
		<span class="reserved">return</span> retrieveByIndex(index,<span class="reserved">this</span>.instructionBoxes);
	}

	<span class="comment">/**
	 * Returns a toolbox by its index
	 * <span class="attrib">@param</span> {Int} index The position of the toolbox in the toolBoxes array. It depends on the order of creation.
	 * <span class="attrib">@return</span> The toolbox corresponding to the given index
	 * <span class="attrib">@type</span> {Object}
	 */</span>		
	<span class="reserved">this</span>.getToolBoxByIndex = <span class="reserved">function</span>(index){
		<span class="reserved">return</span> retrieveByIndex(index,<span class="reserved">this</span>.toolBoxes);
	}
	
	<span class="comment">/**
	 * Sets a profile to the toolbox.
	 * <span class="attrib">@param</span> {Int} profile_id The id of the profile to be loaded
	 * <span class="attrib">@param</span> {String} toolbox_id The toolbox where the profile is going to be loaded
	 * <span class="attrib">@param</span> {Object} properties The properties the tools are going to take, like the propertyBox to show its properties,  
	 * instruction box to show help, hint, and others.
	 */</span>
	<span class="reserved">this</span>.setActiveProfile = <span class="reserved">function</span>(profile_id, toolbox_id, properties){
		var toolbox = <span class="reserved">this</span>.getToolBoxById(toolbox_id);
		toolbox.removeAllTools();
		toolbox.loadProfile(profile_id, properties);
		<span class="reserved">this</span>.activeProfile = profile_id;
	}
	
	<span class="comment">/**
	 * Sets a value to a workspace property.
	 * <span class="attrib">@param</span> {String} property The property that is going to be changed.
	 * <span class="attrib">@param</span> {Any} value The value to set to the property.
	 */</span>
	<span class="reserved">this</span>.setProperty = <span class="reserved">function</span>(property, value){
		switch (property){			
			case <span class="literal">'activeProfile'</span>:
				<span class="reserved">this</span>.activeProfile = value;
				break;
				
			default:
				break;
		}	
	}
	
	<span class="comment">/**
	 * Saves a workspace to the database.
	 */</span>
	<span class="reserved">this</span>.save = <span class="reserved">function</span>(){
		var exists = null;
		var id;
		var workspaceJSON = {};
		
		<span class="reserved">if</span> (<span class="reserved">this</span>.activeProfile) {
			workspaceJSON.current_profile = <span class="reserved">this</span>.activeProfile;
		}<span class="reserved">else</span>{
			var pm = new profileManager();
			profile = pm.createProfile();
			profile.name = <span class="literal">"default"</span>;
			profile.description = <span class="literal">"default"</span>;
			profile.types = ws.toolBoxes[0].toolList;
			profile.save();
			<span class="reserved">this</span>.activeProfile = profile.id; 
			workspaceJSON.current_profile = profile.id;
		}
		workspaceJSON.profiles = <span class="reserved">this</span>.profiles;
		
		<span class="comment">// Building edition areas json</span>
		var editionAreasArray = [];
		var editionAreasJSON = {};
		var editionArea = null;
		<span class="reserved">for</span> (var i =0; i&lt;<span class="reserved">this</span>.editionAreas.length; i++){
			editionArea = <span class="reserved">this</span>.editionAreas[i];
			
			editionAreasJSON.id = editionArea.id;
			editionAreasJSON.title = editionArea.title;
			editionAreasJSON.css_path = editionArea.cssPath;
			editionAreasJSON.top = editionArea.top;
			editionAreasJSON.left = editionArea.left;
			editionAreasJSON.height = editionArea.height;
			editionAreasJSON.width = editionArea.width;
			editionAreasJSON.parent = editionArea.parentId;
			
			editionAreasArray.push(editionAreasJSON);			
		}
		
		workspaceJSON.edition_areas = editionAreasArray; 
		
		<span class="comment">// Building instruction_boxes json</span>
		
		var instructionBoxesArray = [];
		var instructionBoxesJSON = {};
		var instructionBox = null;
		<span class="reserved">for</span> (var i =0; i&lt;<span class="reserved">this</span>.instructionBoxes.length; i++){
			instructionBox = <span class="reserved">this</span>.instructionBoxes[i];
			
			instructionBoxesJSON.id = instructionBox.id;
			instructionBoxesJSON.title = instructionBox.title;
			instructionBoxesJSON.css_path = instructionBox.cssPath;
			instructionBoxesJSON.top = instructionBox.top;
			instructionBoxesJSON.left = instructionBox.left;
			instructionBoxesJSON.height = instructionBox.height;
			instructionBoxesJSON.width = instructionBox.width;
			instructionBoxesJSON.parent = instructionBox.parentId;
			
			instructionBoxesArray.push(instructionBoxesJSON);			
		}
		
		workspaceJSON.instruction_boxes = instructionBoxesArray; 
		
		<span class="comment">// Building property_boxes json</span>
		
		var propertyBoxesArray = [];
		var propertyBoxesJSON = {};
		var propertyBox = null;
		<span class="reserved">for</span> (var i =0; i&lt;<span class="reserved">this</span>.propertyBoxes.length; i++){
			propertyBox = <span class="reserved">this</span>.propertyBoxes[i];
			
			propertyBoxesJSON.id = propertyBox.id;
			propertyBoxesJSON.title = propertyBox.title;
			propertyBoxesJSON.css_path = propertyBox.cssPath;
			propertyBoxesJSON.top = propertyBox.top;
			propertyBoxesJSON.left = propertyBox.left;
			propertyBoxesJSON.height = propertyBox.height;
			propertyBoxesJSON.width = propertyBox.width;
			propertyBoxesJSON.parent = propertyBox.parentId;
			
			propertyBoxesArray.push(propertyBoxesJSON);			
		}
		
		workspaceJSON.property_boxes = propertyBoxesArray;
		

		<span class="comment">// Building tool_boxes json</span>
		
		var toolBoxesArray = [];
		var toolBoxesJSON = {};
		var toolBox = null;
		<span class="reserved">for</span> (var i =0; i&lt; <span class="reserved">this</span>.toolBoxes.length; i++){
			toolBox = <span class="reserved">this</span>.toolBoxes[i];
			
			toolBoxesJSON.id = toolBox.id;
			toolBoxesJSON.title = toolBox.title;
			toolBoxesJSON.css_path = toolBox.cssPath;
			toolBoxesJSON.top = toolBox.top;
			toolBoxesJSON.left = toolBox.left;
			toolBoxesJSON.height = toolBox.height;
			toolBoxesJSON.width = toolBox.width;
			toolBoxesJSON.parent = toolBox.parentId;
			
			toolBoxesArray.push(toolBoxesJSON);			
		}
		
		workspaceJSON.tool_boxes = toolBoxesArray;
		
		var strJSON = JSON.stringify(workspaceJSON);
		
		var params = [];
		params[<span class="literal">'json'</span>] = strJSON;
		
		var myRequest = new request();	
		<span class="reserved">if</span> (<span class="reserved">this</span>.id != null) {
			myRequest.sendSincRequest(<span class="literal">'GET'</span>, null, <span class="literal">"workspaces/"</span> + <span class="reserved">this</span>.id + <span class="literal">"/exist"</span>, <span class="reserved">function</span>(response){
				exists = response;
			});
		}
		
		<span class="comment">// Check if workspace already exists</span>
		<span class="reserved">if</span> ((exists != null) &amp;&amp; JSON.parse(exists)){
			params[<span class="literal">'_method'</span>] = <span class="literal">'PUT'</span>;
	        myRequest.sendSincRequest(<span class="literal">'POST'</span>, params, <span class="literal">"workspaces/"</span> + <span class="reserved">this</span>.id, <span class="reserved">function</span>(response){
			});
		}<span class="reserved">else</span>{
	        myRequest.sendSincRequest(<span class="literal">'POST'</span>, params, <span class="literal">"workspaces"</span>, <span class="reserved">function</span>(response){
				id = response;
			});
			<span class="reserved">this</span>.id = JSON.parse(id);		
		}
	}
	
	<span class="comment">/**
	 * Generates a XML corresponding to the workspace in the database. Save before using this method if you need an up-to-date XML.
	 * <span class="attrib">@return</span> The XML corresponding to this workspace.
	 * <span class="attrib">@type</span> {String}
	 */</span>
	<span class="reserved">this</span>.generateXML = <span class="reserved">function</span>(){
		var workspaceStr;
		var myRequest = new request();
		myRequest.sendSincRequest(<span class="literal">'GET'</span>, null, <span class="literal">"workspaces/"</span> + <span class="reserved">this</span>.id  + <span class="literal">".xml"</span>, <span class="reserved">function</span>(response){
		    workspaceStr = response;
		});
		<span class="reserved">return</span> workspaceStr;   
	}
	
	<span class="comment">/**
	 * Changes the CSS stylesheet associated with a box.
	 * <span class="attrib">@param</span> {Object} box The box to change the CSS stylesheet.
	 * <span class="attrib">@param</span> {String} path The path of the new CSS stylesheet file. It refers to the APP_HOME path constant in the kiwi.js file.
	 */</span>		
	<span class="reserved">this</span>.setCSS = <span class="reserved">function</span>(box, path){
		<span class="comment">// Sets a css file to one of the box in the workspace.</span>
		var documentHead = document.getElementsByTagName(<span class="literal">'head'</span>)[0];	
		
		<span class="comment">// Remove old link tag if it alread exists</span>
		var linkTagExist = false;
		link_tags = documentHead.getElementsByTagName(<span class="literal">'link'</span>);
		<span class="reserved">if</span> (link_tags){
			<span class="reserved">for</span> (var j = 0; j &lt; link_tags.length; j++) {
				<span class="reserved">if</span> (link_tags[j].href == (location.protocol + <span class="literal">"//"</span> + location.hostname + <span class="literal">":"</span> + location.port + APP_HOME + box.cssPath)) {
					link_tags[j].href = APP_HOME + path;
					box.cssPath = path; 
					linkTagExist = true;	
					break;
				}
			}
		}
		
		<span class="reserved">if</span> (!linkTagExist) {
			<span class="comment">// Add new link tag	</span>
			var link = document.createElement(<span class="literal">'link'</span>);
			link.rel = <span class="literal">"stylesheet"</span>;
			link.type = <span class="literal">"text/css"</span>;
			link.href = APP_HOME + path;
			documentHead.appendChild(link);
		}
	}
}

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Mon Feb 21 18:12:28 2011</div>
</body>
</html>
